<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>

<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.util.*"%>
<%@ page import="br.com.hotel.entity.*"%>
<%@ page import="br.com.hotel.dao.*"%>
<%
Long id = Long.parseLong(request.getParameter("id"));

EstadiaDAO c = new EstadiaDAO();
Estadia  e=c.findById(id);
PrecoDAO pdao = new PrecoDAO();
Preco p = pdao.getPreco(e.getDiaria().getId());
double total = 0l;
double dias = Utils.subtractDatas(e.getData_inicial(), e.getData_final())+1;
total += dias*p.getValor();
total += c.getTotalServiceEstadia(e.getId());
e.setTotal(total);

FaturaJSF f = new FaturaJSF();
f.setE(e);

%>


<%@page import="br.com.hotel.bean.Sessao"%>
<%@page import="br.com.hotel.bean.Utils"%>
<%@page import="br.com.hotel.controller.FaturaJSF"%><html>
<f:view>
	<f:loadBundle basename="br.com.hotel.view.faturaParcial" var="msgs" />
	<head>
	<title><h:outputText value="" /></title>
	<link rel="stylesheet" type="text/css" href="dg_content.css">
	<link rel="stylesheet" type="text/css" href="css/listagem.css">
	</head>
	<body>
		<div class="titulo"><h:outputText value="#{msgs.titulo}" /></div>
		<div class="subtitulo"><%out.print("Estadia: "+e); %></div>
		<hr class="linha" noshade="noshade">
		<%out.print("<h2>Cliente: "+e.getCliente().getNome()+"</h2>"); %>
		
		<table border="0" width="100%">
		
		<% 
			out.print("<tr><td class='cabecalho'>Produto</td><td class='cabecalho'>Preço</td><td class='cabecalho'>Quantidade</td><td class='cabecalho'>Total</td></tr>");
		
		int i=1;	
		double total2 = 0.00;
		for(ServiceEstadia se : f.getAllServiceEstadia()){
			total2+=se.getTotal();
			out.print("<tr><td class='linha"+i+"'>"+se.getService().getDescricao()+"</td><td class='linha"+i+"'>"+se.getPreco()+"</td><td class='linha"+i+"'>"+se.getQuantidade()+"</td><td class='linha"+i+"'>"+se.getTotal()+"</td></tr>");
			if(i==1)
			i++;
			else if(i==2) i--;
			}
		out.print("<tr><td class='linha"+i+"'></td><td class='linha"+i+"'></td><td class='linha"+i+"'></td><td class='linha"+i+"'>"+total2+"</td></tr>");
		
			%>
		
		</table>
		<%out.print("<h2>Valor da estadia: "+(e.getTotal()-total2)+"</h2>"); %>
		<h3><%out.print("Total: "+e.getTotal()); %></h3>
		<br />

	</body>
</f:view>
</html>